﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Edit.aspx.cs" Inherits="ZX.WebApp.Edit" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <!--CSS file (default YUI Sam Skin) -->
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/reset-fonts-grids/reset-fonts-grids.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/menu/assets/skins/sam/menu.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/button/assets/skins/sam/button.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/resize/assets/skins/sam/resize.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/layout/assets/skins/sam/layout.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/datatable/assets/skins/sam/datatable.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/paginator/assets/skins/sam/paginator.css" />
    <link href="../Styles/base.css" rel="stylesheet" type="text/css" />
    <!--begin custom header content for this example-->
    <style type="text/css">
    .yui-skin-sam table {
	  width: 100%; 
    }
    
    #button-example-form fieldset,  
    #button-example-form fieldset div {
        border: 2px groove #ccc;
        margin: .5em;
        padding: .5em;
    }
</style>
    <!--end custom header content for this example-->
    <!-- Dependencies -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/datasource/datasource-min.js"></script>
    <!-- OPTIONAL: JSON Utility (for DataSource) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <!-- OPTIONAL: Connection Manager (enables XHR for DataSource) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <!-- OPTIONAL: Get Utility (enables dynamic script nodes for DataSource) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/get/get-min.js"></script>
    <!-- OPTIONAL: Drag Drop (enables resizeable or reorderable columns) -->
    <!-- OPTIONAL: Calendar (enables calendar editors) -->
    <%--<script type="text/javascript" src="../Scripts/yui_2.9.0/build/calendar/calendar-min.js"></script>--%>
    <!-- Source files -->
   <script type="text/javascript" src="../scripts/yui_2.9.0/build/layout/layout-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/button/button-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/container/container-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/resize/resize-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/event-delegate/event-delegate-min.js"></script>
    <script src="../Scripts/yui_3.0/build/yui/yui-min.js" type="text/javascript"></script>
    <script src="../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="../Scripts/Public.js" type="text/javascript"></script>
   <script type="text/javascript">
     var _PageTitle = parent._employeeTitle;
     var SaveFlag = false; //保存是否成功
     var EmployeeID = ""; //当前新增的员工ID

    (function () {
        var Dom = YAHOO.util.Dom,
        Event = YAHOO.util.Event;
        Event.onDOMReady(function () {
            var layout = new YAHOO.widget.Layout({
                units: [
                { position: 'top', height: 35, body: 'toolbar', gutter: '1 1 1 1', scroll: null, zIndex: 2 },
                //{ position: 'left', header: '功能模块', width: 250, body: 'left', gutter: '1 5 1 1', collapse: true, scroll: true, zIndex: 1, resize: true },
                {position: 'center', body: 'data', gutter: '1 1', scroll: true }
 
            ]
            });
            layout.render();
            setInterval(setiFrame, 200);

            var handleSubmit1 = function () {
                var editwindow = document.getElementById("EditUIWindow1");
                if (editwindow) {
                    editwindow.contentWindow.ChooseInfo();
                }
                this.cancel();
                //YAHOO.example.container.dialog2.hide();
            }
        });
    })();

    
    
    function getPar(source, name) {
        var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
        if (reg.test(source)) return RegExp.$2; return "";
    }

    function getPar1(name) {
        var _url = "http://" + document.location;
        return getPar(_url, name);
    }


    function setiFrame() {
        var editwindow = document.getElementById("EditUIWindow");
        var _center = document.getElementById("data");
        editwindow.style.height = document.body.offsetHeight;
    }

    var _fn, _id;
    function ShowDialog(fn, id, src) {
        _fn = fn;
        _id = id;
        document.getElementById("EditUIWindow1").src = src;
        YAHOO.example.container.dialog2.show();
    }

    YAHOO.example.init = function () {
        // "click" event handler for each Button instance
        function onButtonClick(p_oEvent) {
            YAHOO.log("You clicked button: " + this.get("id"), "info", "example1");
            switch (this.get("id")) {
                case "btnSave": //保存
                    handleSubmit();
                    break;
                case "btnClose": //关闭
                    parent.CloseCurPage();
//                    if (getPar1("selfHelp") != "true") {
//                        window.parent.$("#tabs").tabs('close', _PageTitle);
//                    } else {
//                        window.parent.$("#tabs").tabs('close', "我的人事档案");
//                    }
//                    break;
                case "btnSaveAndAddNew": //保存并新增
                    fnSaveAndAdd();
                    break;
                default:
                    break;
            }
        }
        var InitURLPara;
        YAHOO.util.Event.onContentReady("toolbar", function () {
            var btnSave = new YAHOO.widget.Button("btnSave");
            btnSave.on("click", onButtonClick);
            var btnClose = new YAHOO.widget.Button("btnClose");
            btnClose.on("click", onButtonClick);
            var btnReload = new YAHOO.widget.Button("btnSaveAndAddNew");
            btnReload.on("click", onButtonClick);
            InitURLPara = function () {
                var editwindow = document.getElementById("EditUIWindow");
                if (getPar1("selfHelp") != "true") {
                    var para = this.location.search;
                    editwindow.src = "AutoLoadForm.aspx?" + para + "&r=" + Math.random();
                }
                else {
                    document.getElementById("btnSaveAndAddNew").style.display = "none";
                    var url = "AutoLoadForm.aspx?selfHelp=true&entity=hrEmployee&id=<%=this.EmpPropertyValues.EmployeeID %>&deptId=<% =this.EmpPropertyValues.DeptID %>&deptName=<%=this.EmpPropertyValues.DeptName %>&postName=<% =this.EmpPropertyValues.PostName%>&type=1&r=" + Math.random();
                    editwindow.src = url;
                }
            }
            InitURLPara();
            // var btnQuickQuery = new YAHOO.widget.Button("btnQuickQuery");
            // btnQuickQuery.on("click", onButtonClick);
        });
    } ();

var handleSubmit = function () {
    var editwindow = document.getElementById("EditUIWindow");
    if (editwindow) {
        editwindow.contentWindow.Save();
    }
};

var fnSaveAndAdd = function () {
    handleSubmit(); //保存
    if (SaveFlag) { //保存成功后再新增
        var para = this.location.search;
        if (para.indexOf("entity=hrEmployee") > -1) {
            if (para.indexOf("type=3") > -1) {  //新增离职人员
                var parmas = "r=" + Math.random() + "&entity=hrEmployee&type=3";
                var editwindow = document.getElementById("EditUIWindow");
                editwindow.src = "AutoLoadForm.aspx?" + parmas;
            }
            else { //新增在职人员
                var deptId = getPar1("deptId");
                var deptName = getPar1("deptName");
                var parmas = "r=" + Math.random() + "&entity=hrEmployee&deptId=" + deptId + "&deptName=" + deptName + "&type=1";
                var editwindow = document.getElementById("EditUIWindow");
                editwindow.src = "AutoLoadForm.aspx?" + parmas;
            }
            return;
        }

    }
};

//隐藏按钮
var setButtonHiden = function () {
     document.getElementById("btnSave-button").style.display = "none";
    document.getElementById("btnSaveAndAddNew-button").style.display = "none";
};

//隐藏按钮
var setAddNewButtonHiden = function () {
    document.getElementById("btnSaveAndAddNew-button").style.display = "none";
};

/* -----------------------------------------
*  定义对话窗口功能
*  
*
*
*--------------------------------------------*/
YAHOO.namespace("example.container");
YAHOO.util.Event.onDOMReady(function () {
    // Define various event handlers for Dialog
    var handleSubmit = function () {
        var editwindow = document.getElementById("EditUIWindow");
        if (editwindow) {
            editwindow.contentWindow.Save();
        }
    };

    var handleCancel = function () {
        this.cancel();
    };

    var handleSubmit6 = function () {
        var editwindow = document.getElementById("EditUIWindow6");
        if (editwindow) {
            editwindow.contentWindow.Save();
        }
    };

    var handleSubmit1 = function () {
        var editwindow = document.getElementById("EditUIWindow1");
        if (editwindow) {
            editwindow.contentWindow.ChooseInfo();
        }
        this.cancel();
        //YAHOO.example.container.dialog2.hide();
    }
    var handleSuccess = function (o) {
        var response = o.responseText;
        response = response.split("<!")[0];
        document.getElementById("resp").innerHTML = response;
    };
    var handleFailure = function (o) {
        alert("Submission failed: " + o.status);
    };

    // Remove progressively enhanced content class, just before creating the module
    YAHOO.util.Dom.removeClass("dialog2", "yui-pe-content");

    YAHOO.example.container.dialog2 = new YAHOO.widget.Dialog("dialog2",
							    { width: "550px",
							        height: "450px",
							        fixedcenter: true,
							        visible: false,
							        draggable: true,
							        close: true,
							        modal: true,
							        autofillheight: "body",
							        constraintoviewport: true,
							        buttons: [{ text: "确定", handler: handleSubmit1, isDefault: true },
								          { text: "取消", handler: handleCancel}]
							    });
	YAHOO.example.container.dialog6 = new YAHOO.widget.Dialog("dialog6",
							    { width: "750px",
							        height: "450px",
							        fixedcenter: true,
							        modal: true,
							        visible: false,
							        draggable: true,
							        close: true,
							        autofillheight: "body",
							        constraintoviewport: true,
							        buttons: [{ text: "确定", handler: handleSubmit6, isDefault: true },
								          { text: "取消", handler: handleCancel}]
							    });
	YAHOO.example.container.dialog6.callback = { success: handleSuccess,
							        failure: handleFailure
							    };
	YAHOO.example.container.dialog2.render();
	YAHOO.example.container.dialog6.render();
});

// 设置对话框的大小
var SetDWH = function (width, height, dialog) {

    var elements = YAHOO.util.Dom.getElementsByClassName('bd', 'div')[0];
    var w = [],
        h = [];
    w.push(width);
    h.push(height);
    dialog.configWidth(null, w);
    dialog.configHeight(null, h);
    //debugger
    dialog.render();
    if (elements) {
        dialog.fillHeight(elements);
    }
}

//弹出新增劳动合同窗口
function addContract() {
    if (!SaveFlag) {
        alert("请先保存员工信息，再新增合同信息！");
        return;
    }
    if (EmployeeID == "") {
        alert("员工ID获取失败！");
        return;
    }
    //alert(parent.location);
    document.getElementById("dialog6_title").innerHTML = "工作合同信息";
    var condition = "EmployeeID='" + EmployeeID + "'";
    document.getElementById("yui-gen7-button").style.display = 'none';
    document.getElementById("EditUIWindow6").src = "../Extend/YUIDataTableList.aspx?f=d&isShonwBtn=N&functionid=0c9faf7b-7744-4566-954d-9d5d3c9e866a&entity=hrEmployeeContracts&id="+EmployeeID+"&condition=" + condition+"&type=link";   //"AutoLoadForm.aspx?r=" + Math.random() + "&entity=hrEmployeeContract";
    SetDWH(620, 350, YAHOO.example.container.dialog6);
    YAHOO.example.container.dialog6.show();
}
$(document).ready(function () {
    $("#EditUIWindow").height ( $(window).height());
    $("#EditUIWindow").width( $(window).width());
var iframe = document.getElementById("EditUIWindow");
iframe.height = $(window).height();
});
</script> 
</head>
<body class="yui-skin-sam">
    <form id="form1" runat="server">
    <!-- 工具栏 -->
    <div id="listpage">
        <div id="toolbar" style="margin: 2px;">
                    <button type="button" id="btnSave" name="btnSave">
                    保存</button><button type="button" id="btnSaveAndAddNew" name="btnSaveAndAddNew">
                    保存且新增</button> <button type="button" id="btnClose" name="btnClose">
                    关闭</button> 
        </div>
        <div id="data">
            <iframe id="EditUIWindow" name="EditUIWindowName" style="height:600px;width:100%" scrolling="auto" frameborder="0"></iframe>
        </div>
    </div> 

        <div id="dialog2" class="yui-pe-content" >
            <div class="hd">
                选择基本信息:</div>
            <div class="bd" style="-webkit-overflow-scrolling: touch">
                <iframe id="EditUIWindow1" frameborder="0" src="" style="width: 100%; height: 100%;
                    margin: 0px; padding: 0px;"></iframe>
            </div>
      </div>
      <div id="dialog6" class="yui-pe-content"  >
        <div class="hd" id="dialog6_title">
           数据编辑</div>
        <div class="bd">
            <iframe id="EditUIWindow6" frameborder="0" src="" style="width: 100%; height: 100%;
                margin: 0px; padding: 0px;"></iframe>
        </div>
      </div>
    </form>
</body>
</html>

